﻿using System;
using System.Configuration;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ZhimeiSoft.Framework.Client.Configuration
{
    public class ClientConfiguration
    {

        #region 私有字段
        private string _serviceUrl = string.Empty;
        private string _accessMode = string.Empty;
        private string _dbconnectionString = string.Empty;
        private string _comPort = string.Empty;
        #endregion

        #region 属性
        public string DataBaseConnectionString
        {
            get { return _dbconnectionString; }
        }

        public string ServiceUrl
        {
            get { return this._serviceUrl; }
        }

        public string AccessMode
        {
            get { return this._accessMode; }
        }
        public string ComPort
        {
            get { return this._comPort; }
        }
        #endregion

        #region 构造函数

        public ClientConfiguration()
        {
            this._dbconnectionString = ConfigurationManager.ConnectionStrings["CharmManagerDB"].ConnectionString;
            this._serviceUrl = ConfigurationManager.AppSettings["ServiceUrl"];
            this._accessMode = ConfigurationManager.AppSettings["AccessMode"];
            this._comPort = ConfigurationManager.AppSettings["ComPort"];
        }
        #endregion

        public string GetAppSettings(string key)
        {
            if (ConfigurationManager.AppSettings.AllKeys.Contains(key))
            {
                return ConfigurationManager.AppSettings[key];
            }
            else
            {
                return string.Empty;
            }
        }

        public void SetAppSettings(string key, string value)
        {
            //判断key是否存在，如果存在，则修改key的值
            //如果key不存在，则创建一个key
            if (ConfigurationManager.AppSettings.AllKeys.Contains(key))
            {
                ConfigurationManager.AppSettings.Set(key, value);
            }
            else
            {
                ConfigurationManager.AppSettings.Add(key, value);
            }
            
        }

        

    }
}
